{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "a58d890a",
   "metadata": {},
   "source": [
    "# NonlinearFactorGraph\n",
    "\n",
    "## Overview\n",
    "\n",
    "The `NonlinearFactorGraph` class in GTSAM is a key component for representing and solving nonlinear factor graphs. A factor graph is a bipartite graph that represents the factorization of a function, commonly used in probabilistic graphical models. In the context of GTSAM, it is used to represent the structure of optimization problems, e.g., in the domain of simultaneous localization and mapping (SLAM) or structure from motion (SfM).\n",
    "\n",
    "## Key Functionalities\n",
    "\n",
    "### Construction and Initialization\n",
    "\n",
    "- **Constructor**: The class provides a default constructor to initialize an empty nonlinear factor graph.\n",
    "\n",
    "### Factor Management\n",
    "\n",
    "- **add**: This method allows adding a new factor to the graph. Factors represent constraints or measurements in the optimization problem.\n",
    "- **reserve**: Pre-allocates space for a specified number of factors, optimizing memory usage when the number of factors is known in advance.\n",
    "\n",
    "### Graph Operations\n",
    "\n",
    "- **resize**: Adjusts the size of the factor graph, which can be useful when dynamically modifying the graph structure.\n",
    "- **remove**: Removes a factor from the graph, identified by its index.\n",
    "\n",
    "### Querying and Access\n",
    "\n",
    "- **size**: Returns the number of factors currently in the graph.\n",
    "- **empty**: Checks if the graph contains any factors.\n",
    "- **at**: Accesses a specific factor by its index.\n",
    "- **back**: Retrieves the last factor in the graph.\n",
    "- **front**: Retrieves the first factor in the graph."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "71b15f4c",
   "metadata": {},
   "source": [
    "### Optimization and Linearization\n",
    "\n",
    "- **linearize**: Converts the nonlinear factor graph into a linear factor graph at a given linearization point. This is a crucial step in iterative optimization algorithms like [Gauss-Newton](./GaussNewtonOptimizer.ipynb) or [Levenberg-Marquardt](./LevenbergMarquardtOptimizer.ipynb).\n",
    "  \n",
    "  The linearization process involves computing the Jacobian matrices of the nonlinear functions, resulting in a linear approximation:\n",
    "  \n",
    "  $$ f(x) \\approx f(x_0) + A(x - x_0) $$\n",
    "  \n",
    "  where $A$ is the Jacobian matrix evaluated at the point $x_0$."
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
